package gbench.appdemo.jdbcapp.accounting;

import org.junit.jupiter.api.Test;

import gbench.common.fs.XlsFile.DColumn;
import gbench.common.fs.XlsFile.DataMatrix;
import gbench.commonApp.data.DataApp;
import gbench.commonApp.data.DataMatrixApp;
import static gbench.common.tree.LittleTree.*;
import static gbench.common.tree.LittleTree.IRecord.*;
import java.util.stream.Collectors;

public class JunitAcc2 extends DataApp{
    
    @Test
    public void foo() {
        this.cfg.set("url", "jdbc:mysql://localhost:3306/myexchange?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=True");
        this.reload();
        final var recs = jdbc.sql2records(MFT("select * from {0}","T_ACCENTRY"));
        var mm = recs.stream().collect(DataMatrixApp.omc);
        System.out.println(mm);
        System.out.println(mm.shape());
        final var p = mm.reduceColumns(DColumn::getElems,IRecord::REC);
        p.pivotTable("drcr,account").dfs((path,d)->{
            System.out.println(STRING2REC(path)+"\t"+d.map(e->(IRecord)e).collect(Collectors.summarizingDouble(e->e.dbl("amount"))).getMax());
        });;
        System.out.println();
        
    }
    
    @Test
    public void foo2() {
        this.cfg.set("url", "jdbc:mysql://localhost:3306/myexchange?useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=True");
        this.reload();
        final var recs = jdbc.sql2records(MFT("select * from {0}","T_ACCENTRY"));
        final var p = R2C(recs);
        p.pivotTable("drcr,account").dfs((path,d)->{
            System.out.println(STRING2REC(path)+"\t"+d.map(e->(IRecord)e).collect(Collectors.summarizingDouble(e->e.dbl("amount"))).getMax());
        });;
        System.out.println();
        
        System.out.println(p.toString2());
        System.out.println(DataMatrix.fmt(p.toArray2()));
        System.out.println(p.lla("account", e->e));
    }
    
}
